<?php
/**
 * @file
 *  The form related to person
 */

require_once(SHMS_CORE_PATH."/shms_core_common.inc");
require_once(SHMS_CORE_PATH."/shms_core_form.inc");

function shms_get_faculty(){
  return array(
    'science' => "Science",    'engine' => "Engineering",
    'biz'    => "Business",
    'law'    => "Law",
    'dentistry' => "Dentistry",
    'medicine'  => "Medicine",
    'soc'    => "Computing",
    'sde'    => "Design and Environment",
    'arts'   => "Arts and Scoial Sciences",
    'usp'    => "University Scholar Program",
    'music'  => "Music",  );
}

function shms_get_faculty_major(){
  return array(
    'science' => array(
      'maths' => 'Maths',
      'physics' => 'Physics',
      'biology' => 'Biology',
      'chemistry' => 'Chemistry',
      'life science' => 'Life science',
      'statistic' => 'Statistic',
      'food science and technology' => 'Food science and Technology',
      'pharmacy' => 'Pharmacy',
    ),
    'engine' => array(
      'common engineering' => 'Common Engineering',
      'mechanical engineering' => 'Mechanical Engineering',
      'bioengineering' => 'Bioengineering',
      'chemical engineering' => 'Chemical Engineering',
      'engineering science programme' => 'Engineering Science Programme',
      'environmental engineering' => 'Environmental Engineering',
      'computer engineering' => 'Computer Engineering',
      'civil engineering' => 'Civil Engineering',
      'electrical engineering' => 'Electrical Engineering',
      'industrial & systems engineering' => 'Industrial & Systems Engineering',
      'material science & engineering' => 'Material Science & Engineering',
    ),
    'biz' => array(
      'accountancy' => 'Accountancy',
      'business' => 'Business',
    ),
    'law' => array(
      'law' => 'Law',
    ),
    'densitry' => array(
      'dentistry' => 'Dentistry',
    ),
    'medicine' => array(
      'medicine' => 'Medicine',
      'nursing' => 'Nursing',
    ),
    'soc' => array(
      'computing' => 'Computing',
    ),
    'sde' => array(
      'architecture' => 'Architecture',
      'industrial design' => 'Industrial Design',
      'project and facilities management' => 'Project and Facilities Management',
      'real estate' => 'Real estate',
    ),
    'arts' => array(
      'asian studies' => 'Asian Studies',
      'english literature' => 'English Literature',
      'english language' => 'English Language',
      'history' => 'History',
      'philosophy' => 'Philosophy',
      'theatre studies' => 'Theatre Studies',
      'cnm' => 'CNM',
      'economics' => 'Economics',
      'geography' => 'Geography',
      'political science' => 'Political Science',
      'psychology' => 'Psychology',
      'social work' => 'Social Work',
      'sociology' => 'Sociology',
      'others' => 'Others',
    ),
    'usp' => array(
      'usp' => 'USP',
    ),
    'music' => array(
      'music' => 'Music',
    ),
  );
}

/**
 * @return - an array with the basic form structure of the person page.
 *    elements in this array would take the weight 1 ~ 20 (at most)
 */ 
function shms_core_person_form_basic($form = array(),&$form_state = array()){
  $faculty_lst = shms_get_faculty();
  $major_lst = shms_get_faculty_major() + array("empty"=>array());
  $selected = isset($form_state['values']['home_faculty'])?$form_state['values']['home_faculty']:"empty";
  $major_opt = $major_lst[$selected];
  drupal_add_js(SHMS_CORE_PATH."/person_info.js");
  return array(
    'full_name'  => array(
      '#type' => 'textfield',
      '#title' => t("Full Name"),
      '#required' => TRUE,
      '#weight' => 1,
    ),
    'matric_no'  => array(
      '#type' => 'textfield',
      '#title' => t("Matric Number"),
      '#required' => TRUE,
      '#weight' => 2,
    ),
    'gender'  => array(
      '#type' => 'radios',
      '#title' => t("Gender"),
      '#options'  => array(
        '0' => t("Male"),
        '1' => t("Female")
      ),
      '#required' => TRUE,
      '#weight' => 3,
    ),
    'date_of_birth'  => array(
      '#type' => 'date',
      '#title' => t("Date of Birth"),
      '#required' => TRUE,
      '#weight' => 4, 
    ),
    'phone_number'  => array(
      '#type' => 'textfield',
      '#title' => t("Phone Number"),
      '#required' => TRUE,
      '#weight' => 5,
    ),
    'nus_email'  => array(
      '#type' => 'textfield',
      '#title' => t("NUS Email"),
      '#required' => TRUE,
      '#weight' => 6,
    ),
    'personal_email'  => array(
      '#type' => 'textfield',
      '#title' => t("Personal Email"),
      '#required' => TRUE,
      '#weight' => 7,
    ),
    'residential_status'  => array(
      '#type' => 'radios',
      '#title' => t("Residential Status"),
      '#options'  => array(
        'local' => t("Singaporean"),
        'PR' => t("Permanent Resident"),
        'foreigner' => t("International Student")
      ),
      '#required' => TRUE,
      '#weight' => 8,
    ),
    'nationality'  => array(
      // TODO: can change to select later, with a list of countries provided.
      '#type' => 'textfield', 
      '#title' => t("Nationality"),
      '#required' => TRUE,
      '#weight' => 9,
      '#states' => array(),
    ),
    
    'home_faculty'  => array(
      '#type' => 'select', 
      '#title' => t("Home Faculty"),
      '#required' => TRUE,
      '#weight' => 10,
      '#options' => $faculty_lst,
      /*
      '#ajax' => array(
        'callback'=> "shms_core_form_person_faculty_ajax_callback",
        'wrapper' => "shms_person_major",
      ),
       * */
    ),
    /*
    'major'  => array(
      '#type' => 'select', 
      '#title' => t("Major".($selected != 'empty'?" in ".$faculty_lst[$selected]:":<i>Please Select Faculty First</i>")),
      '#prefix' => "<div id='shms_person_major'>",
      '#suffix' => "</div>",
      '#options' => $major_opt,
      '#required' => TRUE,
      '#weight' => 11,
    ),
    */
    'year_of_intake'  => array(
      '#type' => 'select', 
      '#title' => t("Intake Year"),
      '#required' => TRUE,
      '#options'  => shms_core_common_generate_year_options(10,1),
      '#weight' => 12,
    ),
    'year_of_graduation'  => array(
      '#type' => 'select', 
      '#title' => t("Expected Year of Graduation"),
      '#required' => TRUE,
      '#options'  => shms_core_common_generate_year_options(1,10),
      '#weight' => 13,
    ),
  );
}

function shms_core_form_person_faculty_ajax_callback($form,$form_state){
  return $form['major'];
}

function shms_core_person_form_add_room_number_field_for_basic(&$form,$weight){
  $form['room_number'] = array(
    '#type' => 'textfield',
    '#title'=> t("Room Number"),
    '#description'  => t("Please strictly follows the format: [block_letter][number], the block_letter must be capitalized. e.g.: D108"),
    '#required' => TRUE,
    '#weight'   => $weight,
  );
}

function shms_core_user_has_edit_right_to_person($edit_uid){
  global $user;
  return $edit_uid == $user->uid || $user->uid == 1;
}


